Skip to content

[jaekwang97] WEEK 02 Solutions#2691

Open
JAEKWANG97 wants to merge 2 commits into
DaleStudy:mainfrom
JAEKWANG97:week-02-solutions
Open

[jaekwang97] WEEK 02 Solutions#2691
JAEKWANG97 wants to merge 2 commits into
DaleStudy:mainfrom
JAEKWANG97:week-02-solutions

Conversation

@JAEKWANG97

@JAEKWANG97 JAEKWANG97 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

์ž‘์„ฑ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

๊ฒ€ํ† ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

Important

๋ณธ์ธ ๋‹ต์•ˆ ์ œ์ถœ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋ถ„ PR ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜๋“œ์‹œ ๊ฒ€ํ† ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!

  • ๋ฐ”๋กœ ์ด์ „์— ์˜ฌ๋ผ์˜จ PR์— ๋ณธ์ธ์„ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • ๋ณธ์ธ์ด ๊ฒ€ํ† ํ•ด์•ผํ•˜๋Š” PR์˜ ๋‹ต์•ˆ ์ฝ”๋“œ์— ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ์„ธ์š”.
  • ํ† ์š”์ผ ์ „๊นŒ์ง€ PR์„ ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์Šน์ธํ•ด์ฃผ์„ธ์š”.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Dynamic Programming
  • ์„ค๋ช…: climbStairs ๋ฌธ์ œ๋ฅผ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด ํ˜•ํƒœ๋กœ DP ๋ฐฐ์—ด์„ ์ด์šฉํ•ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค. ํ•˜์œ„ ๋ฌธ์ œ์˜ ํ•ด๋ฅผ ์ด์šฉํ•ด ์ƒ์œ„ ๋ฌธ์ œ์˜ ํ•ด๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ์ „ํ˜•์ ์ธ DP ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: ๋™์ ๊ณ„ํš๋ฒ•์œผ๋กœ k๋ฒˆ์งธ ๊ณ„๋‹จ ์ˆ˜๋ฅผ ์ด์ „ ๋‘ ๊ณ„๋‹จ์˜ ํ•ฉ์œผ๋กœ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Two Pointers, Dynamic Programming, Hash Map / Hash Set
  • ์„ค๋ช…: ๋ฐฐ์—ด์˜ ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ ๋ˆ„์  ๊ณฑ์„ ๋ฏธ๋ฆฌ ๊ณ„์‚ฐํ•ด ๊ฐ ์›์†Œ๋ฅผ ์ œ์™ธํ•œ ๊ณฑ์„ ๊ตฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ, ์ค‘๊ฐ„์— ์ž„์‹œ ๋ฐฐ์—ด์„ ๋‘๊ณ  ๋ถ€๋ถ„ํ•ด๋ฅผ ํ•ฉ์„ฑํ•˜๋Š” DP-like ์ „์ฒ˜๋ฆฌ ํŒจํ„ด์ž…๋‹ˆ๋‹ค. ๋‘ ํฌ์ธํ„ฐ๋กœ ์ˆœํšŒ๋ฅผ ์ด์šฉํ•œ ์ตœ์ ํ™”๋Š” ์•„๋‹ˆ์ง€๋งŒ, ๋ถ€๋ถ„๊ตฌ๊ฐ„์˜ ๋ˆ„์  ์ •๋ณด๋ฅผ ์ด์šฉํ•œ๋‹ค๋Š” ์ ์—์„œ DP ๊ณ„์—ด์— ์†ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(n)

ํ”ผ๋“œ๋ฐฑ: ์™ผ์ชฝ/์˜ค๋ฅธ์ชฝ ๋ˆ„์ ๊ณฑ ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด ๊ฐ ์œ„์น˜์˜ ๊ฒฐ๊ณผ๋ฅผ ๊ณฑํ•ด ๊ตฌํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

  • ํŒจํ„ด: Hash Map / Hash Set, Bit Manipulation
  • ์„ค๋ช…: ๋‘ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž ๋“ฑ์žฅ ํšŸ์ˆ˜๋ฅผ ๋น„๊ตํ•˜๊ธฐ ์œ„ํ•ด ๋ฐฐ์—ด๋กœ ์นด์šดํŠธ๋ฅผ ์„ธ๊ณ  ์ฐจ์ด๋ฅผ ๊ฒ€์‚ฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด์‹œ ๋งต/์„ธํŠธ์˜ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํŒจํ„ด์— ์†ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋ฌธ์ž ์ธ๋ฑ์Šค ๊ณ„์‚ฐ์€ ๊ฐ„์ ‘์ ์œผ๋กœ ๋น„ํŠธ ์—ฐ์‚ฐ๊ณผ ์œ ์‚ฌํ•œ ์ƒ์ˆ˜ ์‹œ๊ฐ„ ์ ‘๊ทผ์„ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n + m)
Space O(1)

ํ”ผ๋“œ๋ฐฑ: ๊ณ ์ • ํฌ๊ธฐ์˜ ์นด์šดํŠธ ๋ฐฐ์—ด๋กœ ๊ฐ ๋ฌธ์ž์˜ ์ฐจ์ด๋ฅผ ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

@DaleSeo

DaleSeo commented Jul 1, 2026

Copy link
Copy Markdown
Member

@JAEKWANG97 #2691 (comment)

@namuuCY namuuCY self-requested a review July 1, 2026 16:59

@namuuCY namuuCY left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์šฐ์„  ์ง€๊ธˆ ํ’€๋ฆฐ ๋ฌธ์ œ๋“ค๊นŒ์ง€์˜ ๋ฆฌ๋ทฐ๋ฅผ ๋‹ฌ์•„๋‘์—ˆ์Šต๋‹ˆ๋‹ค!

Comment on lines +1 to +15
class Solution {
public int climbStairs(int n) {
int[] dp = new int[n + 1];
if (n <= 3) return n;
dp[1] = 1;
dp[2] = 2;
dp[3] = 3;

for (int i = 4; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2];
}

return dp[n];
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DP ์ •์„์ ์ธ ํ’€์ด๋Œ€๋กœ ์ž˜ ํ•˜์‹ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
๋‹ค๋งŒ

  • ๋ช‡ ๋ฒˆ์งธ ํ•ญ์ด ์ดˆ๊ธฐํ•ญ์ด๊ณ , ์ดํ›„ ์–ด๋А ํ•ญ๋ถ€ํ„ฐ ์ ํ™”์‹์ด ์ ์šฉ๋˜๋Š”์ง€ ๋‹ค์‹œ ํ•œ๋ฒˆ ์‚ดํŽด๋ณด์‹œ๋Š” ๊ฒƒ๋„ ์ข‹์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • ์ง€๊ธˆ ์ด ํ’€์ด์—์„œ๋Š” n ์ดํ•˜์˜ ๋ชจ๋“  ๊ฐ’์„ ๋‹ค ์ €์žฅํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ๊ตณ์ด ๋‹ค ์ €์žฅํ•  ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ์š”? ์ €์žฅํ•˜์ง€ ์•Š๋Š” ํ’€์ด๋„ ํ•œ๋ฒˆ ์ƒ๊ฐํ•ด๋ณด์‹œ๋Š”๊ฑฐ ์–ด๋–จ๊นŒ์š”?

Comment on lines +1 to +26
import java.util.*;

class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;
int[] right = new int[n + 1];
int[] left = new int[n + 1];

right[0] = 1;
for (int i = 1; i <= n; i++) {
right[i] = right[i - 1] * nums[i - 1];
}

left[n] = 1;
for (int i = n - 1; i >= 0; i--) {
left[i] = left[i + 1] * nums[i];
}

int[] answer = new int[n];
for (int i = 0; i < n; i++) {
answer[i] = right[i] * left[i + 1];
}

return answer;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋Š” ์ฒ˜์Œ์— ์ž˜๋ชป๋œ ํ’€์ด(๋‚˜๋ˆ—์…ˆ์„ ์‚ฌ์šฉํ•œ)๋กœ ํ’€์—ˆ์—ˆ๋Š”๋ฐ,
@JAEKWANG97 ๋‹˜ ํ’€์ด๋ฅผ ๋ณด๊ณ  ์ œ๊ฐ€ ํ‹€๋ ธ๋‹ค๋Š”๊ฑธ ์•Œ๊ฒŒ๋์–ด์š”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants